/*
 * @Author: [wsn] [1741415861@qq.com]
 * @Date: 2023-04-25 13:10:58
 * @LastEditors: [wsn] [1741415861@qq.com]
 * @LastEditTime: 2023-05-26 11:35:12
 * @FilePath: \202304fgs_project\src\components\threejsTools\Tools\LoadobjModel.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
import { MeshLambertMaterial } from "three";
// export default async function LoadModel(obj: any, mtl: any, x: number, y: number, z: number) {
//   console.log('LoadModel我执行了');

/**加载obj模型 */
// export default async function LoadModel(obj: any, mtl: any) {
//   var objloader = new OBJLoader();//obj加载器
//   var mtlloader = new MTLLoader();//材质文件加载器
//   mtlloader.load(mtl, function (materials) {
//     //obj的模型会和MaterialCreator包含的材质对应起来
//     objloader.setMaterials(materials);
//     objloader.load(obj, function (innerobj) {
//       console.log(innerobj, 'innerobj');
//       // obj.translateY(-1.5);
//       window.threescene.add(innerobj);//返回的组对象插入场景中
//       // obj.children[0].scale.set(135, 135, 135);//网格模型缩放
//       // obj.children[0].scale.set(5, 5, 5);
//       window.meshobj = obj;
//       obj.traverse(function (child: any) {
//         if (child.type === "Mesh") {
//           child.material.emissive = child.material.color;
//           child.material.emissiveMap = child.material.map;
//         }
//       })
//       console.log("obj", obj)
//     })
//   })
// }
export default async function LoadModel(obj: any, mtl: any) {
  var objloader = new OBJLoader();//obj加载器
  var mtlloader = new MTLLoader();//材质文件加载器
  mtlloader.load(mtl, function (materials) {
    //obj的模型会和MaterialCreator包含的材质对应起来
    objloader.setMaterials(materials);
    objloader.load(obj, function (innerobj) {
      // obj.translateY(-1.5);
      window.threescene.add(innerobj);//返回的组对象插入场景中
      // obj.children[0].scale.set(135, 135, 135);//网格模型缩放
      // obj.scale.set(0.001, 0.001, 0.001);
      // obj.position.set(3,0,-3);
      window.meshobj = innerobj;
    })
  })
}
